package com.forest.util;

import cn.hutool.core.util.ObjectUtil;
import com.forest.config.SignatureProperties;
import com.forest.config.EncryptionProperties;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 配置文件属性获取工具
 *
 * @author Administrator
 */
@Component
public class EnvironmentHolder {

    private static Environment evn;

    private static EncryptionProperties encryptionProperties;

    private static SignatureProperties signatureProperties;

    public EnvironmentHolder(Environment env, EncryptionProperties encryptionProperties, SignatureProperties appInfoProperties) {
        EnvironmentHolder.evn = env;
        EnvironmentHolder.encryptionProperties = encryptionProperties;
        EnvironmentHolder.signatureProperties = appInfoProperties;
    }

    public static String getProperty(String key) {
        return evn.getProperty(key);
    }

    public static String getSecretKey() {
        return encryptionProperties.getSecretKey();
    }

    public static String getEncryptionAlgorithm() {
        return encryptionProperties.getEncryptionAlgorithm();
    }

    public static String getIv() {
        return encryptionProperties.getIv();
    }

    public static Boolean getEnableFixedIv() {
        return encryptionProperties.getEnableFixedIv();
    }

    public static SignatureProperties.AppInfo getAppInfo(String appId) {
        return signatureProperties.getById(appId);
    }

    public static boolean getUseBouncyCastle() {
        return ObjectUtil.isNull(encryptionProperties) ? true : encryptionProperties.getUseBouncyCastle();
    }

    public static boolean getThrowException() {
        return ObjectUtil.isNull(encryptionProperties) ? true : encryptionProperties.getThrowException();
    }

    public static String getSignatureHost() {
        return signatureProperties.getHost();
    }

    public static EncryptionProperties getEncryptionProperties() {
        return encryptionProperties;
    }

    public static SignatureProperties getSignatureProperties() {
        return signatureProperties;
    }
}
